/*
 * File Name：ScollerToTop.java
 * Copyright：Copyright 2008-2014 CiWong.Inc. All Rights Reserved.
 * Description： ScollerToTop.java
 * Modify By：res-jianpingliu
 * Modify Date：2014-9-11
 * Modify Type：Add
 */
package com.ciwong.mobilelib.widget.listview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Scroller;
import android.widget.TextView;

import com.ciwong.libs.utils.CWLog;
import com.ciwong.libs.utils.CWResource;
import com.ciwong.libs.utils.CWSys;
import com.ciwong.libs.utils.DateFormat;

/**
 * 下拉刷新的算法
 * 
 * @author     res-jianpingliu
 * @version    ciwong v.1.0 2014-9-11
 * @since      ciwong v.1.0
 */
public class PullRefreshController
{
    /**
     * 正在显示的是header
     */
    public static final int SCROLLBACK_HEADER = 0;

    /**
     * 正在显示的是footer
     */
    public static final int SCROLLBACK_FOOTER = 1;

    /**
     * 正常状态
     */
    public static final int SCROLLBACK_NONE = 2;

    /**
     * 滑动时间
     */
    public static final int SCROLL_DURATION = 500; // scroll back duration

    /**
     * 上拉更新更多的阀门值 
     */
    public static final int PULL_LOAD_MORE_DELTA = 3; // when pull up >= 50px
                                                       // at bottom, trigger
                                                       // load more.
    /**
     * 下拉刷新的阀门值 
     */
    public static final float OFFSET_RADIO = 3.0f; // support iOS like pull
    // -- header view
    private CWListViewHeader mHeaderView;
    
    // -- footer view
    private CWListViewFooter mFooterView;
    
    private RelativeLayout mHeaderViewContent;

    private TextView mHeaderTimeView;

    //private int mHeaderViewHeight; // header view's height

    private boolean mEnablePullRefresh = true;

    private boolean mPullRefreshing = false; // is refreashing.
    
    private boolean mEnablePullLoad, cacheEnablePullLoad;

    private boolean mPullLoading;

    private boolean mIsFooterReady = false;

    private boolean mIsHeaderScroll;
    
    private String refreshTag;// 刷新时间TAG,用于存储上次更新数据
    
    private long lastRefreshTime;// 上次更新时间
    
    private int mScrollBack;
    
    private float mLastY = -1;
    
    private int mTotalItemCount;
    
    private int lastBottom;
    
    private boolean showHeader;
    
    private PullRefreshListener mListViewListener;
    
    private Context mContext;
    
    private ListView mListView;
    
    private Scroller mScroller;
     
    /**
     * 下拉刷新的算法
     * 
     * @param listView 
     */
    public PullRefreshController(ListView listView)
    {
        mListView = listView;
        refreshTag = listView.getId() + "" + System.currentTimeMillis();
        mContext = listView.getContext();
        mScroller = new Scroller(mContext, new AccelerateDecelerateInterpolator());
        // init header view
        mHeaderView = new CWListViewHeader(mContext);
        mHeaderViewContent = (RelativeLayout) mHeaderView
                .findViewById(CWResource.getId("libs_listview_header_content"));
        mHeaderTimeView = (TextView) mHeaderView.findViewById(CWResource
                .getId("libs_listview_header_time"));

        // init footer view
        mFooterView = new CWListViewFooter(mContext);
        
        lastRefreshTime = -1;
        
    }

    /**
     * 
     * 设置底部视图
     * 
     * @param footerView
     *            底部视图
     */
    public void setFooterView(CWListViewFooter footerView)
    {
        this.mFooterView = footerView;
    }
    
    /**
     * 加载更多失败
     *
     */
    public void failLoadMore()
    {
        if (mPullLoading == true)
        {
            mPullLoading = false;
            setFooterState(CWListViewFooter.STATE_FAIL);
        }
    }
    
    /**
     * 默认刷新时间(设置了refreshTag更好)
     * 
     */
    public void setRefreshTime()
    {
        if (refreshTag != null && !"".equals(refreshTag)
                && lastRefreshTime == -1)
        {
            lastRefreshTime = CWSys.getSharedLong(refreshTag, -1);
        }
        final String refreshTimeStr;
        if (lastRefreshTime == -1)
        {
            lastRefreshTime = System.currentTimeMillis();
            refreshTimeStr = mContext
                    .getString(
                            CWResource
                                    .getStringId("libs_listview_header_last_time_none"));
        }
        else
        {
            refreshTimeStr = DateFormat.getDateString(lastRefreshTime);
        }
        
        setRefreshTime(mContext.getString(
                CWResource.getStringId("libs_listview_header_last_time"),
                refreshTimeStr));
    }
    
    /**
     * 设置刷新时间
     * 
     * @param time 
     */
    public void setRefreshTime(String time)
    {
        mHeaderTimeView.setHint(time);
    }
    
    /**
     * 更新header高度
     * 
     * @param delta 高度
     */
    public void updateHeaderHeight(float delta)
    {
        setHeaderVisiableHeight((int) delta
                + getHeaderVisiableHeight());
        if (mEnablePullRefresh && !mPullRefreshing)
        { // 未处于刷新状态，更新箭头
            if (getHeaderVisiableHeight() > getHeaderViewHeight())
            {
                setHeaderState(CWListViewHeader.STATE_READY);
            }
            else
            {
                setHeaderState(CWListViewHeader.STATE_NORMAL);
            }
        }
    }
    
    /**
     * 重置footer高度
     *
     */
    public void resetFooterHeight()
    {
        mLastY = 0;
        mScrollBack = SCROLLBACK_FOOTER;
    }
    
    /**
     * 重置Header高度
     *
     */
    public void resetHeaderHeight()
    {
        int height = getHeaderVisiableHeight();
        int bottom = mHeaderViewContent.getBottom();
        if (height == 0)
        {
            // not visible.
            return;
        }
        // refreshing and header isn't shown fully. do nothing.
        if (mPullRefreshing && height <= getHeaderViewHeight())
        {
            return;
        }
        int finalHeight = 0; // default: scroll back to dismiss header.
        // is refreshing, just scroll back to show all the header.
        if (mPullRefreshing && height > getHeaderViewHeight())
        {
            finalHeight = getHeaderViewHeight();
        }
        mScrollBack = SCROLLBACK_HEADER;
        
        mScroller.startScroll(0, height, 0, finalHeight - height,
                SCROLL_DURATION);
        // trigger computeScroll
        mListView.invalidate();
    }
    
    /**
     * 更新footer高度
     * 
     * @param height 高度
     * @param delta y坐标
     * @return 应该滑动的y坐标
     */
    public float updateFooterHeight(int height, float delta)
    {
        if (isEnablePullLoad() && !mPullLoading)
        {
            if (height > PULL_LOAD_MORE_DELTA)
            { // height enough to invoke load
              // more.
                setFooterState(CWListViewFooter.STATE_READY);
            }
            else
            {
                setFooterState(CWListViewFooter.STATE_NORMAL);
                if (getFooterState() == CWListViewFooter.STATE_READY_NORMAL)
                {
                    delta = -1;
                }
            }
        }
        return delta;
    }
    
    /**
     * 停止刷新
     *
     */
    public void stopRefresh()
    {
        if (mPullRefreshing)
        {
            mPullRefreshing = false;
            resetHeaderHeight();
        }
        lastRefreshTime = System.currentTimeMillis();
        if (refreshTag != null && !"".equals(refreshTag))
        {
            CWSys.setSharedLong(refreshTag, lastRefreshTime);
        }
    }
    
    /**
     * 停止刷新
     * 
     * @param showFooter  是否显示footer
     */
    public void stopRefresh(boolean showFooter)
    {
        stopRefresh();
        if (!showFooter)
        {
            hideFooter();
        }
        else
        {
            showFooter();
        }
    }
    
    /**
     * 停止加载更多
     *
     */
    public void stopLoadMore()
    {
        if (isPullLoading())
        {
            setPullLoading(false);
            setFooterState(CWListViewFooter.STATE_NORMAL);
        }
    }
    
    /**
     * 停止加载更多
     * 
     * @param showFooter 是否显示footer
     */
    public void stopLoadMore(boolean showFooter)
    {
        stopLoadMore();
        if (!showFooter)
        {
            hideFooter();
        }
        else
        {
            showFooter();
        }
    }
    
    /**
     * 是否开启加载更多的功能
     * 
     * @param enable
     *            是否能用
     */
    public void setPullLoadEnable(boolean enable)
    {
        cacheEnablePullLoad = enable;
        mEnablePullLoad = enable;
        if (!mEnablePullLoad)
        {
            mFooterView.hide();
        }
        else
        {
            mPullLoading = false;
            mFooterView.show();
            mFooterView.setState(CWListViewFooter.STATE_NORMAL);
            // both "pull up" and "click" will invoke load more.
            mFooterView.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    if (mEnablePullLoad)
                    {
                        startLoadMore();
                    }
                }
            });
        }
    }
    
    /**
     * 是否开启下拉刷新的功能
     * 
     * @param enable
     *            是否能用
     */
    public void setPullRefreshEnable(boolean enable)
    {
        mEnablePullRefresh = enable;
        if (!mEnablePullRefresh)
        { // disable, hide the content
            mHeaderViewContent.setVisibility(View.INVISIBLE);
        }
        else
        {
            mHeaderViewContent.setVisibility(View.VISIBLE);
        }
    }
    
    /**
     * 
     * 开始刷新
     * 
     */
    public void startRefresh()
    {
        mHeaderView.setState(CWListViewHeader.STATE_REFRESHING);
        if (mListViewListener != null && !mPullRefreshing)
        {
            mPullRefreshing = true;
            mListViewListener.onRefresh();
        }
        if (mFooterView != null)
        {
            mFooterView.mHintView.setHint(CWResource
                    .getStringId("libs_listview_footer_hint_normal"));
            mEnablePullLoad = cacheEnablePullLoad;
        }
    }
    
    /**
     * 开始加载更多
     *
     */
    public void startLoadMore()
    {
        mFooterView.setState(CWListViewFooter.STATE_LOADING);
        if (mListViewListener != null && !mPullLoading)
        {
            mPullLoading = true;
            mListViewListener.onLoadMore();
        }
    }
    
    /**
     * 设置底部的高度
     * 
     * @param height
     *            高度
     */
    public void setFooterHeight(int height)
    {
        if (mFooterView != null)
        {
            mFooterView.setHeight(height);
        }
    }

    /**
     * 隐藏footer
     * 
     */
    public void hideFooter()
    {
        if (mFooterView != null)
        {
            mFooterView.hide();
            mListView.setFooterDividersEnabled(false);
        }
    }

    /**
     * 显示footer
     */
    public void showFooter()
    {
        if (mFooterView != null)
        {
            mFooterView.show();
            mListView.setFooterDividersEnabled(true);
        }
    }

    /**
     * 数据已全部加载完成
     * 
     */
    public void dataLoadComplete()
    {
        if (mFooterView != null)
        {
            cacheEnablePullLoad = mEnablePullLoad;
            mEnablePullLoad = false;
            mFooterView.mHintView.setHint(CWResource
                    .getStringId("libs_listview_footer_data_load_complete"));
            mFooterView.mProgressBar.setVisibility(View.INVISIBLE);
        }
    }

    public void setPullRrefreshListener(PullRefreshListener l)
    {
        mListViewListener = l;
    }

    /**
     * 下拉刷新、加载更多的接口
     */
    public interface PullRefreshListener
    {
        /**
         * 刷新数据
         * 
         */
        public void onRefresh();

        /**
         * 加载更多
         * 
         */
        public void onLoadMore();
    }

    /**
     * 底部视图的布局
     * 
     * @author res-qqlin
     * 
     */
    public static class CWListViewFooter extends LinearLayout
    {
        /**
         * 正常状态
         */
        public static final int STATE_NORMAL = 0;

        /**
         * 准备状态
         */
        public static final int STATE_READY = 1;

        /**
         * 正在加载状态
         */
        public static final int STATE_LOADING = 2;

        /**
         * 加载失败状态
         */
        public static final int STATE_FAIL = 3;

        /**
         * 正常准备状态
         */
        public static final int STATE_READY_NORMAL = 4;

        private Context mContext;

        private View mContentView;

        private View mProgressBar;

        private TextView mHintView;

        private int height;

        private int state;

        private boolean visible;

        private CWListViewFooter(Context context)
        {
            super(context);
            initView(context);
        }

        private CWListViewFooter(Context context, AttributeSet attrs)
        {
            super(context, attrs);
            initView(context);
        }

        private void setState(int state)
        {
            if (state == STATE_READY)
            {
                ready();
            }
            else if (state == STATE_LOADING)
            {
                loading();
            }
            else if (state == STATE_FAIL)
            {
                failure();
            }
            else
            {
                if (this.state == STATE_READY)
                {
                    state = STATE_READY_NORMAL;
                }
                normal();
            }
            this.state = state;
        }

        private int getState()
        {
            return state;
        }

        // public void setBottomMargin(int height)
        // {
        // if (height < 0)
        // return;
        // LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)
        // mContentView
        // .getLayoutParams();
        // lp.bottomMargin = height;
        // mContentView.setLayoutParams(lp);
        // }
        //
        // public int getBottomMargin()
        // {
        // LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)
        // mContentView
        // .getLayoutParams();
        // return lp.bottomMargin;
        // }

        private void ready()
        {
            // mHintView.setVisibility(View.VISIBLE);
            mHintView.setText(CWResource
                    .getStringId("libs_listview_footer_hint_ready"));
            mProgressBar.setVisibility(View.INVISIBLE);
        }

        /**
         * normal status
         */
        private void normal()
        {
            // mHintView.setVisibility(View.VISIBLE);
            mHintView.setText(CWResource
                    .getStringId("libs_listview_footer_hint_normal"));
            mProgressBar.setVisibility(View.INVISIBLE);
        }

        /**
         * loading status
         */
        private void loading()
        {
            // mHintView.setVisibility(View.GONE);
            mHintView.setText(CWResource
                    .getStringId("libs_listview_header_hint_loading"));
            mProgressBar.setVisibility(View.VISIBLE);
        }

        private void failure()
        {
            mHintView.setText(CWResource
                    .getStringId("libs_listview_footer_hint_fail"));
            mProgressBar.setVisibility(View.INVISIBLE);
        }

        /**
         * hide footer when disable pull load more
         */
        private void hide()
        {
            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mContentView
                    .getLayoutParams();
            lp.height = 0;
            mContentView.setLayoutParams(lp);
            visible = false;
        }

        /**
         * show footer
         */
        private void show()
        {
            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mContentView
                    .getLayoutParams();
            lp.height = height == 0 ? LayoutParams.WRAP_CONTENT : height;
            mContentView.setLayoutParams(lp);
            visible = true;
        }

        private void setHeight(int height)
        {
            this.height = height;
            show();
        }

        private void initView(Context context)
        {
            mContext = context;
            FrameLayout moreView = (FrameLayout) LayoutInflater
                    .from(mContext)
                    .inflate(CWResource.getLayout("libs_listview_footer"), null);
            height = (int) getContext().getResources().getDimension(
                    CWResource
                            .getDimensionId("libs_listview_def_footer_height"));
            addView(moreView);
            moreView.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

            mContentView = moreView.findViewById(CWResource
                    .getId("libs_listview_footer_content"));
            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mContentView
                    .getLayoutParams();
            lp.height = height;
            mContentView.setLayoutParams(lp);
            mProgressBar = moreView.findViewById(CWResource
                    .getId("libs_listview_footer_progressbar"));
            mHintView = (TextView) moreView.findViewById(CWResource
                    .getId("libs_listview_footer_hint_textview"));
        }
    }

    /**
     * 头部视图布局
     */
    public static class CWListViewHeader extends LinearLayout
    {
        /**
         * 正常状态
         */
        public static final int STATE_NORMAL = 0;

        /**
         * 准备状态
         */
        public static final int STATE_READY = 1;

        /**
         * 正在刷新状态
         */
        public static final int STATE_REFRESHING = 2;

        private final int rotateAnimDuration = 180;

        private LinearLayout mContainer;

        private ImageView mArrowImageView;

        private ProgressBar mProgressBar;

        private TextView mHintTextView;

        private int mState = STATE_NORMAL;

        private Animation mRotateUpAnim;

        private Animation mRotateDownAnim;
        
        private View spliteLine;

        /**
         * 头部视图布局
         * 
         * @param context 上下文
         */
        public CWListViewHeader(Context context)
        {
            super(context);
            initView(context);
        }

        /**
         * 头部视图布局
         * 
         * @param context
         *            上线文
         * @param attrs
         *            属性集合
         */
        public CWListViewHeader(Context context, AttributeSet attrs)
        {
            super(context, attrs);
            initView(context);
        }

        private void initView(Context context)
        {
            final float fromDegrees = 0.0f;
            final float toDegrees = -180.0f;
            
            final float pivotType = 0.5f;
            
            // 初始情况，设置下拉刷新view高度为0
            LayoutParams lp = new LayoutParams(
                    LayoutParams.FILL_PARENT, 0);
            mContainer = (LinearLayout) LayoutInflater.from(context).inflate(
                    CWResource.getLayout("libs_listview_header"), null);
            addView(mContainer, lp);
            setGravity(Gravity.BOTTOM);
            
            spliteLine = findViewById(CWResource
                    .getId("libs_listview_header_splite"));
            mArrowImageView = (ImageView) findViewById(CWResource
                    .getId("libs_listview_header_arrow"));
            mHintTextView = (TextView) findViewById(CWResource
                    .getId("libs_listview_header_hint_textview"));
            mProgressBar = (ProgressBar) findViewById(CWResource
                    .getId("libs_listview_header_progressbar"));

            mRotateUpAnim = new RotateAnimation(fromDegrees, toDegrees,
                    Animation.RELATIVE_TO_SELF, pivotType,
                    Animation.RELATIVE_TO_SELF, pivotType);
            mRotateUpAnim.setDuration(rotateAnimDuration);
            mRotateUpAnim.setFillAfter(true);
            mRotateDownAnim = new RotateAnimation(toDegrees, fromDegrees,
                    Animation.RELATIVE_TO_SELF, pivotType,
                    Animation.RELATIVE_TO_SELF, pivotType);
            mRotateDownAnim.setDuration(rotateAnimDuration);
            mRotateDownAnim.setFillAfter(true);
        }

        private void setState(int state)
        {
            if (state == mState)
            {
                return;
            }
            if (state == STATE_REFRESHING)
            {
                // 显示进度
                mArrowImageView.clearAnimation();
                mArrowImageView.setVisibility(View.INVISIBLE);
                mProgressBar.setVisibility(View.VISIBLE);
            }
            else
            {
                // 显示箭头图片
                mArrowImageView.setVisibility(View.VISIBLE);
                mProgressBar.setVisibility(View.INVISIBLE);
            }

            switch (state)
            {
                case STATE_NORMAL:
                    if (mState == STATE_READY)
                    {
                        mArrowImageView.startAnimation(mRotateDownAnim);
                    }
                    if (mState == STATE_REFRESHING)
                    {
                        mArrowImageView.clearAnimation();
                    }
                    mHintTextView.setText(CWResource
                            .getStringId("libs_listview_header_hint_normal"));
                    break;
                case STATE_READY:
                    if (mState != STATE_READY)
                    {
                        mArrowImageView.clearAnimation();
                        mArrowImageView.startAnimation(mRotateUpAnim);
                        mHintTextView
                                .setText(CWResource
                                        .getStringId("libs_listview_header_hint_ready"));
                    }
                    break;
                case STATE_REFRESHING:
                    mHintTextView.setText(CWResource
                            .getStringId("libs_listview_header_hint_loading"));
                    break;
                default:
            }

            mState = state;
        }

        /**
         * 设置显示区域高度
         * 
         * @param height
         *            高度
         */
        private void setVisiableHeight(int height)
        {
            if (height < 0)
            {
                height = 0;
            }
            LayoutParams lp = (LayoutParams) mContainer
                    .getLayoutParams();
            lp.height = height;
            mContainer.setLayoutParams(lp);
        }

        /**
         * 获取显示区域的高度
         * 
         * @return 高度
         */
        private int getVisiableHeight()
        {
            LayoutParams lp = (LayoutParams) mContainer
                    .getLayoutParams();
            int height = lp.height;
            return height;
        }
        
        @Override
        public boolean dispatchTouchEvent(MotionEvent ev)
        {
            return true;
        }
        
        public void needShowSpliteLine(boolean need)
        {
            spliteLine.setVisibility(need ? View.VISIBLE : View.GONE);
        }
    }
    
    public void showHeaderSpliteLine(boolean need)
    {
        mHeaderView.needShowSpliteLine(need);
    }

    /**
     * 禁止下拉刷新和加载更多功能
     * 
     */
    public void freezeRefreshAndLoadMore()
    {
        mListView.removeHeaderView(mHeaderView);
        mListView.removeFooterView(mFooterView);
        setPullLoadEnable(false);
        setPullRefreshEnable(false);
    }
    
    /**
     * 
     * 获取头部的视图
     * 
     * @return 头部的视图
     */
    public CWListViewHeader getHeaderView()
    {
        return mHeaderView;
    }

    /**
     * 
     * 设置头部的视图
     * 
     * @param headerView
     *            头部的视图
     */
    public void setHeaderView(CWListViewHeader headerView)
    {
        this.mHeaderView = headerView;
    }

    /**
     * 
     * 得到底部视图
     * 
     * @return 底部视图
     */
    public CWListViewFooter getFooterView()
    {
        return mFooterView;
    }
    
    public int getHeaderVisiableHeight()
    {
        return mHeaderView.getVisiableHeight();
    }
    
    public int getHeaderViewHeight()
    {
        return mHeaderViewContent.getHeight();
    }
    
    /**
     * 设置header的显示高度
     * 
     * @param h 高度
     */
    public void setHeaderVisiableHeight(int h)
    {
        mHeaderView.setVisiableHeight(h);
    }
    
    public boolean isFooterVisiable()
    {
        return mFooterView.visible;
    }
    
    public int getFooterState()
    {
        return mFooterView.getState();
    }
    
    /**
     * 设置footer的状态
     * 
     * @param state 状态
     */
    public void setFooterState(int state)
    {
        mFooterView.setState(state);
    }
    
    /**
     * 设置header的状态
     * 
     * @param state 状态
     */
    public void setHeaderState(int state)
    {
        mHeaderView.setState(state);
    }
    
    /**
     * 设置点击加载更多的监听
     * 
     * @param onClickListener 点击监听
     */
    public void setOnFooterClickListener(OnClickListener onClickListener)
    {
        mFooterView.setOnClickListener(onClickListener);
    }
    
    public boolean isEnablePullLoad()
    {
        return mEnablePullLoad;
    }
    
    public void setEnablePullLoad(boolean enable)
    {
        mEnablePullLoad = enable;
    }
    
    public boolean isCacheEnablePullLoad()
    {
        return cacheEnablePullLoad;
    }
    
    public void setCacheEnablePullLoad(boolean enable)
    {
        cacheEnablePullLoad = enable;
    }
    
    public boolean isPullLoading()
    {
        return mPullLoading;
    }
    
    public void setPullLoading(boolean loading)
    {
        mPullLoading = loading;
    }
    
    public boolean isFooterReady()
    {
        return mIsFooterReady;
    }
    
    public void setFooterReady(boolean ready)
    {
        mIsFooterReady = ready;
    }
    
    public boolean isHeaderScroll()
    {
        return mIsHeaderScroll;
    }
    
    public void setHeaderScroll(boolean scroll)
    {
        mIsHeaderScroll = scroll;
    }
    
    public boolean isRefreshing()
    {
        return mPullRefreshing;
    }
    
    public void setRefreshing(boolean refreshing)
    {
        mPullRefreshing = refreshing;
    }
    
    public boolean isEnablePullRefresh()
    {
        return mEnablePullRefresh;
    }
    
    public void setEnablePullRefresh(boolean enable)
    {
        mEnablePullRefresh = enable;
    }
    
    public boolean isShowHeader()
    {
        return showHeader;
    }
    
    public void setShowHeader(boolean show)
    {
        showHeader = show;
    }
    
    public void setTotalItemCount(int count)
    {
        mTotalItemCount = count;
    }
    
    public int getTotalItemCount()
    {
        return mTotalItemCount;
    }
    
    public void setScrollBack(int back)
    {
        mScrollBack = back;
    }
    
    public int getScrollBack()
    {
        return mScrollBack;
    }
    
    public void setLastY(float y)
    {
        mLastY = y;
    }
    
    public float getLastY()
    {
        return mLastY;
    }
    
    public void setLastBottom(int bottom)
    {
        lastBottom = bottom;
    }

    public int getLastBottom()
    {
        return lastBottom;
    }
    
    public String getRefreshTag()
    {
        return refreshTag;
    }
    
    public Scroller getScroller()
    {
        return mScroller;
    }

    /**
     * 禁用header
     *
     */
    public void freezeHeader()
    {
        if (mListView != null && mHeaderView != null && mListView.getHeaderViewsCount() > 0)
        {
            try
            {
                mListView.removeHeaderView(mHeaderView);
            }
            catch (Exception e)
            {
                CWLog.e("ljp", "removeHeaderView Exception");
            }
        }
    }
    
    /**
     * 禁用footer
     *
     */
    public void freezeFooter()
    {
        if (mListView != null && mFooterView != null)
        {
            mListView.removeFooterView(mFooterView);
        }
    }
    
}
